package com.cuckoo.mall.network;

import com.bgn.baseframe.network.bean.TDataBean;
import com.bgn.baseframe.utils.Base64;
import com.bgn.baseframe.utils.BasePackageUtil;
import com.bgn.baseframe.utils.BaseStringUtil;
import com.bgn.baseframe.utils.DeviceUtils;
import com.bgn.baseframe.utils.LanguageUtil;
import com.bgn.baseframe.utils.MD5AndSHA1Util;
import com.bgn.baseframe.utils.NetworkUtil;
import com.bgn.baseframe.utils.RSAUtil;
import com.bgn.baseframe.utils.jsontool.GsonUtil;
import com.cuckoo.mall.javabean.Ticket;
import com.cuckoo.mall.thus.manager.UserInfoManager;
import com.cuckoo.mall.javabean.PostAddress;
import com.cuckoo.mall.javabean.CartProductItem;
import com.cuckoo.mall.javabean.Category;
import com.cuckoo.mall.javabean.CreateOrderParms;
import com.cuckoo.mall.javabean.Fliter;
import com.cuckoo.mall.javabean.GoodPropertyItem;
import com.cuckoo.mall.javabean.Goods;
import com.cuckoo.mall.javabean.GoodsListParms;
import com.cuckoo.mall.javabean.MessageActive;
import com.cuckoo.mall.javabean.MessageOrder;
import com.cuckoo.mall.javabean.MessageStateData;
import com.cuckoo.mall.javabean.Order;
import com.cuckoo.mall.javabean.OrderResult;
import com.cuckoo.mall.javabean.Product;
import com.cuckoo.mall.javabean.ProductAttribute;
import com.cuckoo.mall.javabean.SearchResultData;
import com.cuckoo.mall.javabean.UrlBean;
import com.cuckoo.mall.javabean.UserData;
import com.cuckoo.mall.javabean.UserInfo;
import com.google.gson.JsonObject;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 作者：wl on 2017/9/25 18:02
 * 邮箱：wanglun@stosz.com
 */
public class ApiManager {

    private static <T> Observable<T> subscribeOn(Observable<T> observable) {
        return observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }

    private static RetrofitApi getJavaApi() {
        return HttpUtil.getInstance().getHttpApi();
    }

    /***************************************业务逻辑接口**************************************/

    /*list*/

    /*登录*/
    public static Observable<TDataBean<List<Product>>> getProductList(int category_id, int page_index, int page_count) {

        Map<String, String> tsmap = getTsMap();
        tsmap.put("category_id", String.valueOf(category_id));
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<Product>>> observable = getJavaApi().getProductList(tsmap);

        return subscribeOn(observable);
    }

    /*获取订单详情*/
    public static Observable<TDataBean<Order>> getOrderDetailById(String order_number) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("order_number", String.valueOf(order_number));
        signMapData(tsmap);
        Observable<TDataBean<Order>> observable = getJavaApi().getOrderDetailById(tsmap);
        return subscribeOn(observable);
    }

    /*********************************THUS***************************/


    /*登录*/
    public static Observable<TDataBean<UserInfo>> login(String username, String pwd, String ak) {
        JsonObject accountObj = new JsonObject();
        accountObj.addProperty("email", username);
        accountObj.addProperty("password", MD5AndSHA1Util.getMD5(pwd));
        accountObj.addProperty("ak", ak);
        String dataJsonString = accountObj.toString();
        String edata = RSAUtil.getencrptString(dataJsonString);
        //RSAUtil.getdecryptString(edata);

        Map<String, String> infoMap = getInfoJsonObject();
        infoMap.put("data", edata);

        Observable<TDataBean<UserInfo>> observable = getJavaApi().login(infoMap);
        return subscribeOn(observable);
    }

    /*自动登录*/
    public static Observable<TDataBean> autoLogin(String id, String token) {
        JsonObject accountObj = new JsonObject();
        accountObj.addProperty("user_id", id);
        accountObj.addProperty("token", token);

        String dataJsonString = accountObj.toString();
        String edata = RSAUtil.getencrptString(dataJsonString);

        Map<String, String> infoMap = getInfoJsonObject();
        infoMap.put("data", edata);

        Observable<TDataBean> observable = getJavaApi().autoLogin(infoMap);
        return subscribeOn(observable);
    }

    /*注册*/
    public static Observable<TDataBean<UserInfo>> register(String username, String pwd, String ak) {
        JsonObject accountObj = new JsonObject();
        accountObj.addProperty("email", username);
        accountObj.addProperty("password", MD5AndSHA1Util.getMD5(pwd));
        accountObj.addProperty("ak", ak);
        String dataJsonString = accountObj.toString();
        String edata = RSAUtil.getencrptString(dataJsonString);
        Map<String, String> infoMap = getInfoJsonObject();
        infoMap.put("data", edata);
        Observable<TDataBean<UserInfo>> observable = getJavaApi().register(infoMap);
        return subscribeOn(observable);
    }

    /*登录*/
    public static Observable<TDataBean<UserInfo>> thridPartLogin(String facebook_id, String email, String phone, String third_party_id, String nickname, String head_img, String ak) {
        JsonObject accountObj = new JsonObject();
        accountObj.addProperty("facebook_id", BaseStringUtil.warpNullString(facebook_id));
        accountObj.addProperty("email", BaseStringUtil.warpNullString(email));
        accountObj.addProperty("third_party_id", BaseStringUtil.warpNullString(third_party_id));
        accountObj.addProperty("phone", BaseStringUtil.warpNullString(phone));
        accountObj.addProperty("ak", ak);

        String dataJsonString = accountObj.toString();
        String edata = RSAUtil.getencrptString(dataJsonString);
        //RSAUtil.getdecryptString(edata);

        Map<String, String> infoMap = getInfoJsonObject();
        infoMap.put("data", edata);

        infoMap.put("nickname", BaseStringUtil.warpNullString(nickname));
        infoMap.put("head_img", BaseStringUtil.warpNullString(head_img));

        Observable<TDataBean<UserInfo>> observable = getJavaApi().thirdPartLogin(infoMap);
        return subscribeOn(observable);
    }

    /*忘记密码*/
    public static Observable<TDataBean<String>> forgetPasswor(String email) {
        Map<String, String> map = new HashMap<>();
        map.put("email", email);
        Observable<TDataBean<String>> observable = getJavaApi().forgetPasswod(map);
        return subscribeOn(observable);
    }

    /*获取用户信息*/
    public static Observable<TDataBean<UserData>> getUserData() {
        Map<String, String> tsMap = getTsMap();
        signMapData(tsMap);
        Observable<TDataBean<UserData>> observable = getJavaApi().getUserData(tsMap);
        return subscribeOn(observable);
    }


    /*获分类信息*/
    public static Observable<TDataBean<List<Category>>> getAllCategories() {
        Map<String, String> tsmap = getTsMap();
        signMapData(tsmap);
        Observable<TDataBean<List<Category>>> observable = getJavaApi().getAllCategories(tsmap);
        return subscribeOn(observable);
    }

    /*获Home分类信息*/
    public static Observable<TDataBean<List<Category>>> getHomeCategories() {
        Map<String, String> tsmap = getTsMap();

        signMapData(tsmap);
        Observable<TDataBean<List<Category>>> observable = getJavaApi().getHomeCategories(tsmap);
        return subscribeOn(observable);
    }


    /*获取分类下的商品列表*/
    public static Observable<TDataBean<List<Goods>>> getGoodsList(int page_index, int page_count, GoodsListParms parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        if (parms == null) {
            tsmap.put("subcategoryid", "5");
        } else {
            tsmap.put("subcategoryid", parms.getSusubcategoryid());
        }

        if (parms != null && parms.getPropertyItems() != null && parms.getPropertyItems().size() > 0) {
            for (GoodPropertyItem propertyItem : parms.getPropertyItems()) {
                tsmap.put(propertyItem.getName(), propertyItem.getSelectedId());
            }
        }
        signMapData(tsmap);
        Observable<TDataBean<List<Goods>>> observable = getJavaApi().getGoodsList(tsmap);
        return subscribeOn(observable);

    }

    /*搜索商品*/
    public static Observable<TDataBean<SearchResultData>> searchList(int page_index, int page_count, GoodsListParms parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        tsmap.put("key", parms.getKey());
        if (parms.getPropertyItems() != null && parms.getPropertyItems().size() > 0) {
            for (GoodPropertyItem propertyItem : parms.getPropertyItems()) {
                tsmap.put(propertyItem.getName(), propertyItem.getSelectedId());
            }
        }
        signMapData(tsmap);
        Observable<TDataBean<SearchResultData>> observable = getJavaApi().searchList(tsmap);
        return subscribeOn(observable);

    }

    /*获取HOME分类下的商品列表*/
    public static Observable<TDataBean<List<Goods>>> getHomeGoodsList(int page_index, int page_count, GoodsListParms parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        tsmap.put("maincategoryids", parms.getMaincategoryids());
        tsmap.put("subcategoryid", parms.getSusubcategoryid());
        if (parms.getPropertyItems() != null && parms.getPropertyItems().size() > 0) {
            for (GoodPropertyItem propertyItem : parms.getPropertyItems()) {
                tsmap.put(propertyItem.getName(), propertyItem.getSelectedId());
            }
        }
        signMapData(tsmap);
        Observable<TDataBean<List<Goods>>> observable = getJavaApi().getHomeGoodsList(tsmap);
        return subscribeOn(observable);
    }

    /*获取首页推荐列表*/
    public static Observable<TDataBean<List<Goods>>> getHomeRecommonList(int page_index, int page_count) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<Goods>>> observable = getJavaApi().getHomeRecommonList(tsmap);
        return subscribeOn(observable);
    }

    /*获取商品详情*/
    public static Observable<TDataBean<Product>> getGoodInfo(String product_id) {
        Map<String, String> map = getTsMap();
        map.put("product_id", product_id);
        signMapData(map);
        Observable<TDataBean<Product>> observable = getJavaApi().getGoodInfo(map);
        return subscribeOn(observable);
    }

    /*add favorite*/
    public static Observable<TDataBean> addFavorite(String product_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("product_id", product_id);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().addFavorite(tsmap);
        return subscribeOn(observable);

    }

    /*del favorite商品详情*/
    public static Observable<TDataBean> cancleFavorite(String product_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("product_ids", product_id);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().cancleFavorite(tsmap);
        return subscribeOn(observable);
    }


    /*get favoritelist*/
    public static Observable<TDataBean<List<Product>>> getFavoriteList() {
        Map<String, String> tsmap = getTsMap();
        signMapData(tsmap);
        Observable<TDataBean<List<Product>>> observable = getJavaApi().loadFavoriteList(tsmap);
        return subscribeOn(observable);
    }

    /*get cart list*/
    public static Observable<TDataBean<List<CartProductItem>>> loadCartList() {
        Map<String, String> tsmap = getTsMap();
        signMapData(tsmap);
        Observable<TDataBean<List<CartProductItem>>> observable = getJavaApi().loadCartList(tsmap);
        return subscribeOn(observable);
    }

    /*add to cart*/
    public static Observable<TDataBean> addToCart(String product_id, int number, List<ProductAttribute> parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("product_id", product_id);
        tsmap.put("number", String.valueOf(number));

        if (parms != null && parms.size() > 0) {
            JsonObject jsonObject = new JsonObject();
            for (ProductAttribute propertyItem : parms) {
                jsonObject.addProperty(propertyItem.getName(), propertyItem.getSelectedValue());
            }
            tsmap.put("attribute", Base64.encode(GsonUtil.toJson(jsonObject).getBytes()));
        }
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().addToCart(tsmap);
        return subscribeOn(observable);
    }

    /*get favoritelist*/
    public static Observable<TDataBean> removeFromCart(String card_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("cart_ids", card_id);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().removeFromCart(tsmap);
        return subscribeOn(observable);
    }

    /* updateCartItemNums*/
    public static Observable<TDataBean> updateCartItemNums(String cart_id, int cart_num) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("cart_id", cart_id);
        tsmap.put("cart_num", String.valueOf(cart_num));
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().updateCartItemNums(tsmap);
        return subscribeOn(observable);
    }

    /* from cart to favorite*/
    public static Observable<TDataBean> moveToFavarite(String cart_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("cart_id", cart_id);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().moveToFavorite(tsmap);
        return subscribeOn(observable);
    }

    /* create oeder*/
    public static Observable<TDataBean<OrderResult>> createOrder(CreateOrderParms parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("cart_ids", parms.getCart_ids());
        tsmap.put("email", parms.getEmail());
        tsmap.put("name", parms.getName());
        tsmap.put("phone", parms.getPhone());
        tsmap.put("remarks", parms.getRemarks());
        tsmap.put("province", parms.getProvince());
        tsmap.put("city", parms.getCity());
        tsmap.put("address", parms.getAddress());
        tsmap.put("post_code", parms.getZip_code());
        if (parms.getCoupon_id() != 0) {
            tsmap.put("coupon_id", String.valueOf(parms.getCoupon_id()));
        }
        signMapData(tsmap);
        Observable<TDataBean<OrderResult>> observable = getJavaApi().createOrder(tsmap);
        return subscribeOn(observable);
    }

    /* create oeder*/
    public static Observable<TDataBean<OrderResult>> createOrderByProduc(CreateOrderParms parms) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("product_id", parms.getProduct_id());
        tsmap.put("attribute", parms.getAttribute());
        tsmap.put("number", String.valueOf(parms.getNumber()));

        tsmap.put("email", parms.getEmail());
        tsmap.put("name", parms.getName());
        tsmap.put("phone", parms.getPhone());
        tsmap.put("remarks", parms.getRemarks());
        tsmap.put("province", parms.getProvince());
        tsmap.put("city", parms.getCity());
        tsmap.put("address", parms.getAddress());
        tsmap.put("post_code", parms.getZip_code());
        if (parms.getCoupon_id() != 0) {
            tsmap.put("coupon_id", String.valueOf(parms.getCoupon_id()));
        }
        signMapData(tsmap);
        Observable<TDataBean<OrderResult>> observable = getJavaApi().createOrderByProduc(tsmap);
        return subscribeOn(observable);
    }

    /* set oeder cod*/
    public static Observable<TDataBean<Order>> setOrderCOD(String order_num) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("order_num", order_num);
        signMapData(tsmap);
        Observable<TDataBean<Order>> observable = getJavaApi().setOrderCOD(tsmap);
        return subscribeOn(observable);
    }

    /* set oeder cod*/
    public static Observable<TDataBean<List<Order>>> loadOrderList(String is_pay, int page_index, int page_count) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("is_pay", is_pay);
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<Order>>> observable = getJavaApi().loadOrderList(tsmap);
        return subscribeOn(observable);
    }

    /* set oeder cod*/
    public static Observable<TDataBean> deleteOrder(String order_num) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("order_number", order_num);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().deleteOrder(tsmap);
        return subscribeOn(observable);
    }

    /* set oeder cod*/
    public static Observable<TDataBean> modifyUserInfo(String nickname) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("nick_name", nickname);
//        tsmap.put("ismale", "female".equals(userData.getSex()) ? "0" : "1");
//        tsmap.put("email", userData.getEmail());
//        tsmap.put("phone", userData.getPhone());
//        tsmap.put("country", userData.getCountry());
//        tsmap.put("zip_code", userData.getZip_code());
//        tsmap.put("state", userData.getState());
//        tsmap.put("city", userData.getCity());
//        tsmap.put("address", userData.getAddress());
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().modifyUserInfo(tsmap);
        return subscribeOn(observable);
    }

    /* upload image*/
    public static Observable<TDataBean<UrlBean>> uploadHeadImage(File file) {

        Map<String, String> tsmap = getTsMap();
        signMapData(tsmap);
        Map<String, RequestBody> params = new HashMap<>();
        params.put("user_id", toRequestBody(tsmap.get("user_id")));
        params.put("ts", toRequestBody(tsmap.get("ts")));
        params.put("sign", toRequestBody(tsmap.get("sign")));
        params.put(getKeyName("img", file.getName()), RequestBody.create(MediaType.parse("image/jpg"), file));
        Observable<TDataBean<UrlBean>> observable = getJavaApi().uploadHeadImage(params);
        return subscribeOn(observable);
    }

    /* input invite code*/
    public static Observable<TDataBean> inputInViteCode(String code) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("code", code);
        signMapData(tsmap);
        Observable<TDataBean> observable = getJavaApi().inputInViteCode(tsmap);
        return subscribeOn(observable);
    }

    /* check new message*/
    public static Observable<TDataBean<MessageStateData>> checkNewMessage(String activity_id, String order_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("activity_id", activity_id);
        tsmap.put("order_id", order_id);
        signMapData(tsmap);
        Observable<TDataBean<MessageStateData>> observable = getJavaApi().checkNewMessage(tsmap);
        return subscribeOn(observable);
    }

    /*  active message list*/
    public static Observable<TDataBean<List<MessageActive>>> getMessageActiveList(int page_index, int page_count) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<MessageActive>>> observable = getJavaApi().getMessageActiveList(tsmap);
        return subscribeOn(observable);
    }

    /* order message*/
    public static Observable<TDataBean<List<MessageOrder>>> getMessageOrderList(int page_index, int page_count) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<MessageOrder>>> observable = getJavaApi().getMessageOrderList(tsmap);
        return subscribeOn(observable);
    }

    /* order RecommndList*/
    public static Observable<TDataBean<List<Goods>>> getGoodDetaildRecommndList(String product_id) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("product_id", product_id);
        signMapData(tsmap);
        Observable<TDataBean<List<Goods>>> observable = getJavaApi().getGoodDetaildRecommndList(tsmap);
        return subscribeOn(observable);
    }


    /* order RecommndList*/
    public static Observable<TDataBean<List<Product>>> getRecentlyViewdList(int page_index, int page_count) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("page_index", String.valueOf(page_index));
        tsmap.put("page_count", String.valueOf(page_count));
        signMapData(tsmap);
        Observable<TDataBean<List<Product>>> observable = getJavaApi().getRecentlyViewdList(tsmap);
        return subscribeOn(observable);
    }

    /* result category*/
    public static Observable<TDataBean<List<Fliter>>> getSearchResultCategory(String key) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("key", key);
        signMapData(tsmap);
        Observable<TDataBean<List<Fliter>>> observable = getJavaApi().getSearchResultCategory(tsmap);
        return subscribeOn(observable);
    }

    /* result category*/
    public static Observable<TDataBean<PostAddress>> getAddressByCode(String code) {
        Map<String, String> tsmap = getTsMap();
        tsmap.put("post_code", code);
        signMapData(tsmap);
        Observable<TDataBean<PostAddress>> observable = getJavaApi().getAddressByCode(tsmap);
        return subscribeOn(observable);
    }

    /* get all ticket*/
    public static Observable<TDataBean<List<Ticket>>> getAllTickets() {
        Map<String, String> tsmap = getTsMap();
        signMapData(tsmap);
        Observable<TDataBean<List<Ticket>>> observable = getJavaApi().getAllTickets(tsmap);
        return subscribeOn(observable);
    }

    /**********************************************************固定封装的一些常用map****************************************************************/
    /*PartMap的文件键名需要特殊处理*/
    public static String getKeyName(String key, String fileName) {
        return key + "\"; filename=\"" + fileName;
    }


    public static Map<String, String> getSignMap(String... datas) {
        HashMap<String, String> signMap = new HashMap<>();
        long ts = System.currentTimeMillis() / 1000L;
        String sign = BaseStringUtil.getSignString(String.valueOf(UserInfoManager.getInstance().getUserInfo().getUser_id()), String.valueOf(ts), UserInfoManager.getInstance().getUserInfo().getToken(), datas);
        signMap.put("user_id", String.valueOf(UserInfoManager.getInstance().getUserInfo().getUser_id()));
        signMap.put("sign", sign);
        signMap.put("ts", String.valueOf(ts));
        return signMap;
    }


    public static void signMapData(Map<String, String> dataMap) {
        if (UserInfoManager.getInstance().isLogin()) {
            dataMap.put("user_id", String.valueOf(UserInfoManager.getInstance().getUserInfo().getUser_id()));
            String sign = BaseStringUtil.getSignString(UserInfoManager.getInstance().getUserInfo().getToken(), dataMap);
            dataMap.put("sign", sign);
        }
    }

    public static Map<String, String> getTsMap() {
        int ts = (int) (System.currentTimeMillis() / 1000L);
        HashMap<String, String> tsMap = new HashMap<>();
        tsMap.put("ts", String.valueOf(ts));
        return tsMap;
    }

    public static Map<String, Object> getObjectTsMap() {
        int ts = (int) (System.currentTimeMillis() / 1000L);
        HashMap<String, Object> tsMap = new HashMap<>();
        tsMap.put("ts", String.valueOf(ts));
        return tsMap;
    }

    public static Map<String, String> getInfoJsonObject() {
        String lang = LanguageUtil.getSavedLanguage2Country();
        String uuid = DeviceUtils.getDeviceId();
        String devicetoken = "";
        String device_platform = "android";
        String device_type = DeviceUtils.getDeviceBrand();
        String os_version = DeviceUtils.getSystemVersion();
        String app_version = BasePackageUtil.getVersionName();
        String network = NetworkUtil.getNetworkerStatusName();
        long ts = System.currentTimeMillis() / 1000L;

        HashMap<String, String> infoMap = new HashMap<>();
        infoMap.put("lang", lang);
        infoMap.put("uuid", uuid);
        infoMap.put("devicetoken", devicetoken);
        infoMap.put("device_platform", device_platform);
        infoMap.put("device_type", device_type);
        infoMap.put("os_version", os_version);
        infoMap.put("app_version", app_version);
        infoMap.put("network", network);
        infoMap.put("ts", String.valueOf(ts));
        return infoMap;
    }

    public static RequestBody toRequestBody(String value) {
        RequestBody body = RequestBody.create(MediaType.parse("text/plain"), value);
        return body;
    }
}
